#ifndef __SUBSCRIBER_PUBLISHER_HH__
#define __SUBSCRIBER_PUBLISHER_HH__

#include <list>
#include <boost/weak_ptr.hpp>

namespace Common
{

namespace Patterns
{
	class Subscriber
	{
		public:
			typedef boost::shared_ptr< Subscriber > Ptr;
			typedef boost::weak_ptr< Subscriber > WeakPtr;

		public:
			virtual ~Subscriber() {};

			virtual void notify() = 0;
	};

	class Publisher
	{
		public:
			typedef boost::shared_ptr< Publisher > Ptr;

		private:
			std::list< Subscriber::WeakPtr > iSubscribers;

		protected:
			void detachDeletedSubscribers();

		public:
			virtual ~Publisher() {};

			void attach( Subscriber::Ptr aSubscriber );
			void detach( Subscriber::Ptr aSubscriber );

			void notifySubscribers();
	};

}

}

#endif
